//
//  EmotionKeyBoard.m
//  Weibo
//
//  Created by Anasue on 9/25/15.
//  Copyright (c) 2015 Anasue. All rights reserved.
//

#import "EmotionKeyBoard.h"
#import "EmotionListView.h"
#import "EmotionToolBar.h"
#import "EmotionTool.h"
#import "MJExtension.h"

@interface EmotionKeyBoard ()<EmotionToolBarDelegate>
@property (nonatomic, weak) EmotionListView *listView;
@property (nonatomic, weak) EmotionToolBar *toolBar;

@end

@implementation EmotionKeyBoard



#pragma mark - 初始化
- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {        
        //创建表情View
        EmotionListView *listView = [[EmotionListView alloc]init];
        listView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithName:@"emoticon_keyboard_background"]];
        [self addSubview:listView];
        self.listView = listView;
        //创建表情条
        EmotionToolBar *toolBar = [[EmotionToolBar alloc]init];
        toolBar.delegate = self;
        [self addSubview:toolBar];
        self.toolBar = toolBar;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat toolBarX = 0;
    CGFloat toolBarW = ScreenW;
    CGFloat toolBarH = 35;
    CGFloat toolBarY = self.size.height - toolBarH;
    self.toolBar.frame = CGRectMake(toolBarX, toolBarY, toolBarW, toolBarH);
    CGFloat listViewX = 0;
    CGFloat listViewY = 0;
    CGFloat listViewW = toolBarW;
    CGFloat listViewH = toolBarY;
    self.listView.frame = CGRectMake(listViewX, listViewY, listViewW, listViewH);
}

#pragma mark - EmotionToolBarDelegate
- (void)emotionToolBar:(EmotionToolBar *)toolBar didClickBtn:(EmotionType)emotionType
{
    switch (emotionType) {
        case EmotionTypeDefault:
            self.listView.emotions = [EmotionTool defaultEmotions];
            break;
        case EmotionTypeEmoji:
            self.listView.emotions = [EmotionTool emojiEmotions];
            break;
        case EmotionTypeLxh:
            self.listView.emotions = [EmotionTool lxhEmotions];
            break;
        case EmotionTypeRecent:
            self.listView.emotions = [EmotionTool recentEmotions];
            break;
        default:
            break;
    }
}

@end
